﻿Imports System
Imports System.Data
Imports MySql.Data
Imports MySql.Data.MySqlClient

Public Class clsDatabase
    Private AppStrings As New clsAppStrings

    Public Sub DisConnect(ByVal ActiveConnection As MySqlConnection)
        ActiveConnection.Close()
    End Sub

    Public Function Connect() As MySqlConnection
        Dim CS As String = AppStrings.MySQLServerConnectionStr
        Using Conn As New MySqlConnection(CS)
            Try
                Conn.Open()
                Return Conn
            Catch ex As MySqlException
                Return Nothing
            Finally
                Conn.Close()
            End Try
        End Using
    End Function

    Public Function TestConnection() As Boolean
        Dim TCS As String = AppStrings.MySQLServerConnectionStr
        Using TConn As New MySqlConnection(TCS)
            Try
                TConn.Open()
                Return True
            Catch ex As MySqlException
                Return False
            Finally
                TConn.Close()
            End Try
        End Using
    End Function

    Public Function ExecuteSQLCommand(ByVal SQL As String, ByVal DBConnection As MySqlConnection) As MySqlDataAdapter
        If DBConnection.State = ConnectionState.Closed Then
            DBConnection.Open()
        End If
        Dim DBA As New MySqlDataAdapter(SQL, DBConnection)

        Return DBA
    End Function
End Class
